package com.deli.springboot.quartz.sendMessage;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;

public class SendMeassageScheduler {
    public static void main(String[] args) throws SchedulerException, InterruptedException {
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //1.创建一个jobdetail实例，将该实例与job.class绑定
        JobDetail jobDetail = JobBuilder.newJob(SendMessageJob.class)
                .withIdentity("sendMessageJob", "quartz").usingJobData("message","这是值1").usingJobData("shortValue",100).build();

        //2.创建一个trigger实例，用来出发job的执行方式
        //立即执行，每隔两秒执行一次
        CronTrigger trigger = (CronTrigger)TriggerBuilder.newTrigger()
                .withIdentity("sendMessageTrigger", "quartz")

                .withSchedule(CronScheduleBuilder.cronSchedule("* * * * * ? *"))
//                .usingJobData("triggerMessage","trigger值1")
//                .usingJobData("triggerMessageDouble","trigger值2")
                .build();
        //3.创建scheduler实例，通过反射来创建
        SchedulerFactory factory = new StdSchedulerFactory();
        Scheduler scheduler = factory.getScheduler();
        scheduler.start();

        scheduler.scheduleJob(jobDetail, trigger);
        Thread.sleep(2000L);
        scheduler.standby();
        scheduler.shutdown();
    }
}
